<?php
class Student extends Zend_Db_Table{
	protected $_name ="student";
	protected $_primary = 'student_id';

    public function getTopStudents(){
		$select = $this->select();
		$select->limit('10');
		$select->order('student_id desc');
		return $this->fetchAll($select)->toArray();
    }
    
    public function getAllstudentInArray($array){
		$where=" student_id in (".implode(',',$array).")";
		$select = $this->select();
		$select->where($where);
		$select->order('student_id desc');
		$sql = $select->__toString();
		return $this->fetchAll($select)->toArray();
    }
    
 	//根据student_id 查询student
    public function getStudentBystudent_id($student_id){
		$select = $this->select();
		$select->where("student_id=".$student_id);
		return $this->fetchAll($select)->toArray();
    }
	
	//根据student_name 查询student
    public function getStudentBystudent_name($student_name){
		$select = $this->select();
		$select->where("name='".$student_name."'");
		return $this->fetchAll($select)->toArray();
    }

	//根据class_id 查询student
    public function getStudentByclass_id($class_id){
		$select = $this->select();
		$select->where("class_id=".$class_id);
		return $this->fetchAll($select)->toArray();
    }

	//根据class_id 查询student
    public function getStudentBycompany_id($company_id,$page,$perpage){
		$select = $this->select();
		$select->where("company_id=".$company_id);
		$select->order('student_id desc');
        if($page!=9999){
			$select->limitPage($page,$perpage);
		}
		return $this->fetchAll($select)->toArray();
    }

	//根据学生的名字模糊查询学生表
	public function getstudentLikename($student_name){
		$select = $this->select();
		$select->where("name like %".$student_name."%");
  		return $this->fetchAll($select)->toArray();
	}
	
	//查询所有student
    public function getAllStudents($page,$perpage,$search_name){
		$where = "1=1";
		if($search_name!=""){
			$where.=" and name like '%$search_name%'";
		}
		$select = $this->select();
		$select->where($where);
		$select->order('student_id desc');
		if($page!=""){
			$select->limitPage($page,$perpage);
		}
		return $this->fetchAll($select)->toArray();
    }

    public function getAllStudentsexcel(){
		$where = "1=1";
		$select = $this->select();
		$select->where($where);
		$select->order('student_id asc');
		return $this->fetchAll($select)->toArray();
    }
    
	//更新student
    public function updateStudentBySid($array,$student_id){
		$db = $this->getAdapter();
		$where=$db->quoteInto('student_id = ?', $student_id);
		$this->update($array, $where);
		return true;
	}
	
	//删除student
	public function delStudentBystudent_id($student_id){
		$where = 'student_id = '. $student_id;
		$this->delete($where);
		return true;
    }
}

